//
//  UIButton+Extension.swift
//  sinaWeiBo
//
//  Created by smartlei on 15/10/15.
//  Copyright © 2015年 smartlei. All rights reserved.
//

import UIKit

//对垒扩展
extension UIButton {
    

    /// MARK - 扩展“便利”构造函数
    convenience init(imgName: String,backImgName: String) {
        //首先初始化
        self.init()
        //设置
        setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        setImage(UIImage(named: imgName + "_highlighted"), forState: UIControlState.Highlighted)
        
        //设置背景颜色
        setBackgroundImage(UIImage(named: backImgName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImgName + "_highlighted"), forState: UIControlState.Highlighted)
        
        //自动调整宽高
        sizeToFit()
    }
    /// MARK - 扩展“便利”构造函数
    //titleColor: UIColor = UIColor.orangeColor() 缺省值时取该至数值
    convenience init(title: String, titleColor: UIColor = UIColor.orangeColor() , backImgName: String) {
        
        //调用父类构造函数，初始化
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(titleColor, forState: UIControlState.Normal)
        
        setBackgroundImage(UIImage(named: backImgName), forState: UIControlState.Normal)
        
        sizeToFit()
    }
    /// MARK - 扩展“便利”构造函数
    //titleColor: UIColor = UIColor.orangeColor() 缺省值时取该至数值
    convenience init(title: String,fontSize: CGFloat ,titleColor: UIColor = UIColor.orangeColor() , imgName: String) {
        
        //调用父类构造函数，初始化
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(titleColor, forState: UIControlState.Normal)
        
        setImage(UIImage(named: imgName), forState: UIControlState.Normal)
    
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        
        sizeToFit()
    }
    
    
}



